/*******************************************************************************
*  Project      : Minigate Golfin                                 
*  Program ID   : home.js                                 
*  Description  : 클럽개별메인 
*
********************************************************************************
*  Program History                                                            
*  Date        Author    Description                                          
*  ----------  --------  -------------------------------------------------------- 
*  2012-06-20  이윤노    Created.  
*  2012-06-00  이윤노    Complete.  
*******************************************************************************/

jQuery(function($){

	// 동호회 이름
	function clsClubName()
	{
		this._HTMLDom = null;
		this._ERRMSG = {
			"_NOVALUE": "동호회 이름을 입력해 주십시요."
			, "_INVALID": "동호회 이름은 2~20자 이내로 입력해 주십시요."
			, "_DUPLICATE": "중복확인을 하십시요."
		}
		this._clubData = {
			"클럽명": null
			, "중복유무": null
		}
		this.errMsg = null;
		this._init();
	}
	
	clsClubName.prototype = {
		_init: function(){
			this._HTMLDom = {
				"$layer": $("div#container section#main_content div.golf_board div.club_creat table tbody tr:eq(0) td input:text")
			}
		}
		, getValue: function(){
			return this._HTMLDom["$layer"].val();
		}
		, setValue: function(val){
			this._HTMLDom["$layer"].val(val);
			this.clubName = val;
		}
		, isValid: function(){
			var $layer = this._HTMLDom["$layer"];
			var val = $layer.val();
			var reg = /^.{2,20}$/ig;
			
			if(val.length == 0){
				this.errMsg = this._ERRMSG["_NOVALUE"];
				return false;
			}else if(!reg.test(val)){
				this.errMsg = this._ERRMSG["_INVALID"];
				return false;
			}else if(!this._clubData["중복유무"]){
				if(this.clubName == this.getValue()) return true;
				this.errMsg = this._ERRMSG["_DUPLICATE"];
				return false;
			}
			
			return true;
		}
		, getError: function(){
			return this.errMsg;
		}
		, focus: function(){
			this._HTMLDom["$layer"].trigger("focus");
		}
		, $getBtnDuplicate: function(){
			return 	this._HTMLDom["$layer"].parent().find("a");
		} 
		, setClubData: function(key,val){
			this._clubData[key] = val;
		}
	}
	
	// 동호회 소개
	function clsClubIntro()
	{
		this._HTMLDom = null;
		this._ERRMSG = {
			"_NOVALUE": "동호회 소개를 입력해 주십시요."
			, "_INVALIDLEN": "동호회 소개는 40자 이내로 입력해 주십시요."
			, "_INVALIDEXP": "특수문자(!@#$%^&*)가 입력되어 있습니다."
		}
		this.errMsg = null;
		this._init();
		this.clubName = null;
	}
	
	clsClubIntro.prototype = {
		_init: function(){
			this._HTMLDom = {
				"$layer": $("div#container section#main_content div.golf_board div.club_creat table tbody tr:eq(1) td input:text")
			}
		}
		, getValue: function(){
			return this._HTMLDom["$layer"].val();
		}
		, setValue: function(val){
			this._HTMLDom["$layer"].val(val);
			this.clubName = val;
		}
		, isValid: function(){
			var $layer = this._HTMLDom["$layer"];
			var val = $layer.val();
			var regLen = /^.{2,20}$/ig;
			var regExp = /[ㄱ-ㅎㅏ-ㅣ가-힣A-Za-zx0-9]$/ig;			
			
			if(val.length == 0){
				this.errMsg = this._ERRMSG["_NOVALUE"];
				return false;
			}else if(!regLen.test(val)){
				this.errMsg = this._ERRMSG["_INVALIDLEN"];
				return false;
			}else if(!regExp.test(val)){
				this.errMsg = this._ERRMSG["_INVALIDEXP"];
				return false;
			}
			
			return true;
		}
		, getError: function(){
			return this.errMsg;
		}
		, focus: function(){
			this._HTMLDom["$layer"].trigger("focus");
		}
	}
	
	// 승인여부
	function clsApproval()
	{
		this._HTMLDom = null;
		this._ERRMSG = {
			"_NOVALUE": "승인여부를 선택해 주십시요."
			,"_NOCOMMENT":"가입 질문을 입력하여 주세요."
			,"_INVALIDLEN":"30자 이내로 입력하여 주세요."
		}
		this.errMsg = null;
		this._init();
	}
	
	clsApproval.prototype = {
		_init: function(){
			var thisClass = this;
			
			this._HTMLDom = {
				"$layer": $("div#container section#main_content div.golf_board div.club_creat table tbody tr:eq(2) td input:radio")
				, "$comment": $("div#container section#main_content div.golf_board div.club_creat table tbody tr:eq(2) td input:text")
			}
			
			this._HTMLDom["$layer"].each(function(n){
				$(this).attr("name", "rdoApproval");
			});
			
			this._bind();
		}
		, getValue: function(){
			return this._HTMLDom["$layer"].eq(0).is(":checked");
		}
		, setValue: function(val){
			this._HTMLDom["$layer"].eq((val=="N"?0:1)).prop("checked",true);
			if(val=="N") this._HTMLDom["$comment"].prop("readonly",true);
		}
		, setComment: function(val){
			this._HTMLDom["$comment"].val(val);
		}
		, isValid: function(){
			var $layer = this._HTMLDom["$layer"];
			var $comment = this._HTMLDom["$comment"];
			var val = this.getValue();
			var n = $layer.index($layer.filter(":checked"));
			var regLen = /^.{0,30}$/ig;
			
			if($layer.filter(":checked").length == 0){
				this.errMsg = this._ERRMSG["_NOVALUE"];
				return false;
			}else if($comment.val().length == 0 &&  n == 1){
				this.errMsg = this._ERRMSG["_NOCOMMENT"];
				return false;
			}else if(!regLen.test($comment.val())){
				this.errMsg = this._ERRMSG["_INVALIDLEN"];
				return false;
			}
			
			return true;
		}
		, getError: function(){
			return this.errMsg;
		}
		, focus: function(){
			this._HTMLDom["$layer"].eq(0).trigger("focus");
		}
		, getComment: function(){
			return this._HTMLDom["$comment"].val();
		}
		, _bind: function(){
			var thisClass = this;
			var $layer = this._HTMLDom["$layer"];
			var $comment = this._HTMLDom["$comment"];
			
			$layer.change(function(event){
				var n = $layer.index($layer.filter(":checked"));
				if(n){
					 $comment.prop("readonly",false);
				}else {
					 $comment.prop("readonly",true);
					 $comment.val("");
				}
			});	
		}
	}
	
	//키워드
	function clsKeyword(){
		this._HTMLDom = null;
		this._ERRMSG = {
			"_NOKEYWORD1": "키워드 1번항목을 입력해 주십시요."
			, "_NOKEYWORD2": "키워드 2번항목을 입력해 주십시요."
			, "_NOKEYWORD3": "키워드 3번항목을 입력해 주십시요."
			, "_FOCUS": ""
		}
		this.errMsg = null;
		this._init();
	}
	
	clsKeyword.prototype = {
		_init: function(){
			this._HTMLDom = {
				"$layer": $("div#container section#main_content div.golf_board div.club_creat table tbody tr:eq(3) td input:text")
			}
		}	
		, getValue: function(){
			var result  = "";
			
			for(var i=0;i<this._HTMLDom["$layer"].length;++i){
				if(result != "") result += ",";
				result += this._HTMLDom["$layer"][i].value;
			}
			
			return result;
		}
		, setValue: function(val){
			var $layer = this._HTMLDom["$layer"];
			if(val){
				var $tmp = val.split(",");
				if($tmp.length>=3 ) $layer.eq(2).val($tmp[2]);
				if($tmp.length>=2 ) $layer.eq(1).val($tmp[1]);
				if($tmp.length>=1 ) $layer.eq(0).val($tmp[0]);
			}			
		}
		, isValid: function(){
			var $layer = this._HTMLDom["$layer"];
			var val = this.getValue().split(",");
			var regLen = /^.{2,20}$/ig;
			
			if($layer.eq(0).val().length == 0) {
				this.errMsg =  this._ERRMSG["_NOKEYWORD1"];
				this._ERRMSG["_FOCUS"] = 0;
				return false;
			}			
			if($layer.eq(1).val().length == 0) {
				this.errMsg =  this._ERRMSG["_NOKEYWORD2"];
				this._ERRMSG["_FOCUS"] = 1;
				return false;
			}			
			if($layer.eq(2).val().length == 0) {
				this.errMsg =  this._ERRMSG["_NOKEYWORD3"];
				this._ERRMSG["_FOCUS"] = 2;
				return false;
			}
			
			return true;	
		}
		, getError: function(){
			return this.errMsg;
		}
		, focus: function(){
			var $layer = this._HTMLDom["$layer"];
			var n = this._ERRMSG["_FOCUS"];
			
			this._HTMLDom["$layer"].eq(n).trigger("focus");
		}
	}
	
	// 카테고리
	function clsCategory()
	{
		this._HTMLDom = null;
		this._ERRMSG = {
			"_NOVALUE": "카테고리를 선택해 주십시요."
		}
		this._RDOValue = [
			"1", "2", "3", "4", "5"
		];
		this.cateoryKey = null;
		this.errMsg = null;
		this._init();
	}
	
	clsCategory.prototype = {
		_init: function(){
			var thisClass = this;
			
			this._HTMLDom = {
				"$layer": $("div#container section#main_content div.golf_board div.club_creat table tbody tr:eq(4) td")
			}
			
			this._HTMLDom["$layer"].each(function(n){
				$(this).attr("name", "rdoCategory").val(thisClass._RDOValue[n]);
			});
		}
		, getValue: function(){
			return this.categoryKey;
		}
		, setValue: function(val){
			this.categoryKey = val["카테고리키"];
			this._HTMLDom["$layer"].contents().filter(function(){
				return (this.nodeType==3&&this.data.trim());
			}).after(val["카테고리명"]).remove();					
		}
		, isValid: function(){
			var $layer = this._HTMLDom["$layer"];
			var val = this.getValue();
			
			if(!val){
				this.errMsg = this._ERRMSG["_NOVALUE"];
				return false;
			}
			
			return true;
		}
		, getError: function(){
			return this.errMsg;
		}
		, focus: function(){
			this._HTMLDom["$layer"].eq(0).trigger("focus");
		}
	}
	
	// 상단스킨
	function clsSkin()
	{
		this._HTMLDom = null;
		this._ERRMSG = {
			"_NOVALUE": "상단스킨을 선택해 주십시요."
			, "_NOIMAGE": "이미지를 직접 등록해 주십시요."
		}
		this.errMsg = null;
		this._FILE = {
			 "파일키": null
			, "섬네일": null
			, "파일명": null
			, "원본파일명": null
		}
		
		this._init();
	}
	
	clsSkin.prototype = {
		_init: function(){
			var thisClass = this;
			
			this._HTMLDom = {
				"$layer": $("div#container section#main_content div.golf_board div.club_creat table tbody tr:eq(6) td")
				, "$image": $("div#container section#main_content div.golf_board div.club_creat table tbody tr:eq(6) td img:first")
			}
			
			var p = this.$getBtnSubmit().position();
			_gf.setUploadFileImage(this.$getBtnSubmit(), null, function(ret){
				thisClass.setCustomImgUrl(ret["파일리스트"][0]);
			},{
				"left": p["left"]
				, "top": p["top"]	-20
			});
			
			// 라디오버튼 value값 설정
			this._HTMLDom["$layer"].find("input:radio").each(function(n){
				var $img = $(this).parent().next("img");
				var src = $img.attr("src");
				
				if(n == 0){
					$(this).attr("name", "rdoSkin").val("").click(function(event){
						var val = thisClass.getValue();
						
						if(!val) thisClass.$getBtnSubmit().trigger("click");
					});
				}else{
					$(this).attr("name", "rdoSkin").val(src).click(function(event){
						thisClass._FILE["선택파일"] = src;
					});
				}
			});
		}
		, getValue: function(){
			var $layer = this._HTMLDom["$layer"];
			var idx = $layer.find("input:radio").index($layer.find("input:radio:checked"));
			if(idx){			
				return $layer.find("p>img").eq(idx).attr("src");
			}else {
				return this._FILE["파일키"] + "," + this._FILE["섬네일"] + "," + this._FILE["파일명"] + "," + this._FILE["원본파일명"];
			}
			
			//return this._FILE["파일키"] + "," + this._FILE["섬네일"] + "," + this._FILE["파일명"] + "," + this._FILE["원본파일명"];
		}			
		, setValue: function(idx,val){
			this._HTMLDom["$layer"].find("input:radio").eq(idx).prop("checked",true);
			if(idx == 0){
				this._FILE = val;
				this._HTMLDom["$layer"].find("img:eq(0)").eq(0).attr({
					"src": val["파일명"]
					, "width": 225
	      			, "height": 70
				});
			}
		}	
		, isValid: function(){
			var $layer = this._HTMLDom["$layer"];
			var val = this.getValue();			
			if(this.getIdx()<0 ) {
				this.errMsg = this._ERRMSG["_NOVALUE"];
				return false;
			}else if(this.getIdx()==0 && !this._FILE["파일명"]){
				this.errMsg = this._ERRMSG["_NOIMAGE"];
				return false;
			}
								
			return true;
		}
		, getError: function(){
			return this.errMsg;
		}
		, $getBtnSubmit: function(){
			return this._HTMLDom["$layer"].find("span.ma_left5 a img");
		}
		, focus: function(){
			this._HTMLDom["$layer"].filter("input:radio:first").trigger("focus");
		}
		// 파일전송 완료 후
		, setCustomImgUrl: function(ret){
			this._FILE = ret;
			this._FILE["파일키"] = "NOT";
			this._FILE["섬네일"] = "NOT";
			
			var imgUrl = _gf.filePath2Url(ret["파일명"]);
			
			this._HTMLDom["$layer"].find("input:radio").eq(0).prop("checked",true);
			this._HTMLDom["$layer"].find("img:eq(0)").eq(0).attr({
				"src": imgUrl
				, "width": 400
				, "height": 70
			});
			_gf.spinEnd();
		}
		, getIdx: function(){
			return this._HTMLDom["$layer"].find("input:radio").index(this._HTMLDom["$layer"].find("input:radio:checked"));
		}
	}
	
	// 배너이미지
	function clsBanner()
	{
		this._HTMLDom = null;
		this._ERRMSG = {
			"_NOVALUE": "배너를 선택해 주십시요."
			, "_NOIMAGE": "배너 이미지를 직접 등록해 주십시요."
		}
		this.errMsg = null;
		this._FILE = {
			 "파일키": null
			, "섬네일": null
			, "파일명": null
			, "원본파일명": null
		}
		
		this._init();
	}
	
	clsBanner.prototype = {
		_init: function(){
			var thisClass = this;
					
			this._HTMLDom = {
				"$layer": $("div#container section#main_content div.golf_board div.club_creat table tbody tr:eq(7) td")
				, "$image": $("div#container section#main_content div.golf_board div.club_creat table tbody tr:eq(7) td img:first")
			}
			
			var p = this.$getBtnSubmit().position();
			
			_gf.setUploadFileImage(this.$getBtnSubmit(), null, function(ret){
				thisClass.setCustomImgUrl(ret["파일리스트"][0]);
			},{
				"left": p["left"]
				, "top": p["top"]	-20
			});
			
			// 라디오버튼 value값 설정
			this._HTMLDom["$layer"].find("input:radio").each(function(n){
				var $img = $(this).parent().next();
				var src = $img.attr("src");
				
				if(n == 0){
					$(this).attr("name", "rdoBanner").val("").click(function(event){
						var val = thisClass.getValue();
						
						if($.browser.msie && !val){
							alert("파일을 직접 등록해 주십시요.");
						}else{
							if(!val) thisClass.$getBtnSubmit().trigger("click");
						}
					});
				}else{
					$(this).attr("name", "rdoBanner").val(src).click(function(event){
						thisClass._FILE["선택파일"] = src;
					});
				}
			});			
		}
		, getValue: function(){
			var $layer = this._HTMLDom["$layer"];
			var idx = $layer.find("input:radio").index($layer.find("input:radio:checked"));
			if(idx){			
				return $layer.find("p>img").eq(idx).attr("src");
			}else {
				return this._FILE["파일키"] + "," + this._FILE["섬네일"] + "," + this._FILE["파일명"] + "," + this._FILE["원본파일명"];
			}
			//return this._FILE["파일키"] + "," + this._FILE["섬네일"] + "," + this._FILE["파일명"] + "," + this._FILE["원본파일명"];
		}		
		, setValue: function(idx,val){			
			this._HTMLDom["$layer"].find("input:radio").eq(idx).prop("checked",true);
			if(idx == 0){
				this._FILE = val;
				this._HTMLDom["$layer"].find("img:eq(0)").eq(0).attr({
					"src": val["파일명"]
					, "width": 225
	      			, "height": 70
				});
			}
		}			
		, isValid: function(){
			var $layer = this._HTMLDom["$layer"];
			var val = this.getValue();
			
			if(this.getIdx()<0 ) {
				this.errMsg = this._ERRMSG["_NOVALUE"];
				return false;
			}else if(this.getIdx()==0 && !this._FILE["파일명"]){
				this.errMsg = this._ERRMSG["_NOIMAGE"];
				return false;
			}
								
			return true;
		}
		, getError: function(){
			return this.errMsg;
		}
		, $getBtnSubmit: function(){
			return this._HTMLDom["$layer"].find("span.ma_left5 a>img");
		}
		, focus: function(){
			this._HTMLDom["$layer"].filter("input:radio:first").trigger("focus");
		}
		// 파일전송 완료 후
		, setCustomImgUrl: function(ret){
			this._FILE = ret;
			this._FILE["파일키"] = "NOT";
			this._FILE["섬네일"] = "NOT";
			
			var imgUrl = _gf.filePath2Url(ret["파일명"]);
			
			this._HTMLDom["$layer"].find("input:radio").eq(0).prop("checked",true);
			this._HTMLDom["$layer"].find("img:eq(0)").eq(0).attr({
				"src": imgUrl
				, "width": 225
      			, "height": 70
			});
			_gf.spinEnd();			
		}
		, getIdx: function(){
			return this._HTMLDom["$layer"].find("input:radio").index(this._HTMLDom["$layer"].find("input:radio").filter(":checked"));
		}
	}
	
	// 로고이미지
	function clsLogo()
	{
		this._HTMLDom = null;
		this._ERRMSG = {
			"_NOVALUE": "로고를 선택해 주십시요."
			, "_NOIMAGE": "로고 이미지를 직접 등록해 주십시요."
		}
		this.errMsg = null;
		this._FILE = {
			 "파일키": null
			, "섬네일": null
			, "파일명": null
			, "원본파일명": null
		}
		
		this._init();
	}
	
	clsLogo.prototype = {
		_init: function(){
			var thisClass = this;
					
			this._HTMLDom = {
				"$layer": $("div#container section#main_content div.golf_board div.club_creat table tbody tr:eq(8) td")
				, "$image": $("div#container section#main_content div.golf_board div.club_creat table tbody tr:eq(8) td img:first")
			}
			
			var p = this.$getBtnSubmit().position();
			_gf.setUploadFileImage(this.$getBtnSubmit(), null, function(ret){
				thisClass.setCustomImgUrl(ret["파일리스트"][0]);
			},{
				"left": p["left"]
				, "top": p["top"]	-20
			});
			
			// 라디오버튼 value값 설정
			this._HTMLDom["$layer"].find("input:radio").each(function(n){
				var $img = $(this).parent().next();
				var src = $img.attr("src");
				
				if(n == 0){
					$(this).attr("name", "rdoLogo").val("").click(function(event){
						var val = thisClass.getValue();
						
						if($.browser.msie && !val){
							alert("파일을 직접 등록해 주십시요.");
						}else{
							if(!val) thisClass.$getBtnSubmit().trigger("click");
						}
					});
				}else{
					$(this).attr("name", "rdoLogo").val(src).click(function(event){
						thisClass._FILE["선택파일"] = src;
					});
				}
			});			
		}
		, getValue: function(){
			var $layer = this._HTMLDom["$layer"];
			var idx = $layer.find("input:radio").index($layer.find("input:radio:checked"));
			if(idx){			
				return $layer.find("img").eq(idx).attr("src");
			}else {
				return this._FILE["파일키"] + "," + this._FILE["섬네일"] + "," + this._FILE["파일명"] + "," + this._FILE["원본파일명"];
			}
			
			//return this._FILE["파일키"] + "," + this._FILE["섬네일"] + "," + this._FILE["파일명"] + "," + this._FILE["원본파일명"];
		}		
		, setValue: function(idx,val){			
			this._HTMLDom["$layer"].find("input:radio").eq(idx).prop("checked",true);
			if(idx == 0){
				this._FILE = val;
				this._HTMLDom["$layer"].find("img:eq(0)").eq(0).attr({
					"src": val["파일명"]
					, "width": 50
	      			, "height": 50
				});
			}
		}			
		, isValid: function(){
			var $layer = this._HTMLDom["$layer"];
			var val = this.getValue();
			
			if(this.getIdx()<0 ) {
				this.errMsg = this._ERRMSG["_NOVALUE"];
				return false;
			}else if(this.getIdx()==0 && !this._FILE["파일명"]){
				this.errMsg = this._ERRMSG["_NOIMAGE"];
				return false;
			}
								
			return true;
		}
		, getError: function(){
			return this.errMsg;
		}
		, $getBtnSubmit: function(){
			return this._HTMLDom["$layer"].find("span.ma_left5 a>img");
		}
		, focus: function(){
			this._HTMLDom["$layer"].filter("input:radio:first").trigger("focus");
		}
		// 파일전송 완료 후
		, setCustomImgUrl: function(ret){
			this._FILE = ret;
			this._FILE["파일키"] = "NOT";
			this._FILE["섬네일"] = "NOT";
			
			var imgUrl = _gf.filePath2Url(ret["파일명"]);
			
			this._HTMLDom["$layer"].find("input:radio").eq(0).prop("checked",true);
			this._HTMLDom["$layer"].find("img:eq(0)").eq(0).attr({
				"src": imgUrl
				, "width": 50
      			, "height": 50
			});
			_gf.spinEnd();			
		}
		, getIdx: function(){
			return this._HTMLDom["$layer"].find("input:radio").index(this._HTMLDom["$layer"].find("input:radio:checked"));
		}
	}
	
	function clsComm()
	{
		this.clubNameRequest = null;
		
		this._init();
	}
	
	clsComm.prototype = {
		_init: function(){
			this.clubNameRequest = {
				"클럽명": null
			}	
		}	
//------------------------ 동호회명중복확인------------------------//	
		, clubNameDuplicate: function(){
			var thisClass = this;
			
			// ajax 시작			
			//parameter setting and run
			_gf.ajax({
				"sid":"CL001",
				"servicename":"checkClubName"
			}, {
				"clubName": this.clubNameRequest["클럽명"]				
			}, function(ret){
				// callback and mapping
				var resData = {
					"응답코드": (ret["msp"]["contents"]["serviceResult"] == "00000"?true:false)
					, "메세지": _gf.getResultMsg(ret)
					, "클럽명" : thisClass.clubNameRequest["클럽명"]
				}
				$(thisClass).trigger("evtFinishClubNameDuplicate", [resData]);
			});
			// ajax 끝			
		}
		, setClubNameRequest: function(key, val){
			this.clubNameRequest[key] = val;	
		}
//------------------------ 동호회명중복확인------------------------//			
//------------------------ 동호회수정------------------------//
		, clubSubmit: function(arg){
			var thisClass = this;
			
			// ajax 시작			
			//parameter setting and run
			_gf.ajax({
				"sid":"CL001",
				"servicename":"update"
			}, {
				 "clubSeq": arg["동호회키"]
				, "clubName": arg["동호회이름"]
				, "clubDesc": arg["동호회소개"]
				, "acceptYn": arg["가입승인여부"]
				, "acceptQuestion": arg["가입승인질문"]
				, "clubKeyword": arg["키워드"]
				, "categoryId": arg["카테고리"]
				, "skinUrl": arg["상단스킨"]
				, "skinGb": arg["상단스킨구분"]
				, "bannerUrl": arg["배너이미지"]
				, "bannerGb": arg["배너이미지구분"]
				, "logoUrl": arg["로고이미지"]
				, "logoGb": arg["로고이미지구분"]
				
			}, function(ret){				
				// callback and mapping
				var resData = {
					"응답코드": (ret["msp"]["contents"]["serviceResult"] == "00000"?true:false)
					, "메세지": _gf.getResultMsg(ret)	
					, "클럽명" : thisClass.clubNameRequest["클럽명"]			
				}				
				//$(thisClass).trigger("evtFinishClubSubmit", [resData]);
			});
			// ajax 끝		
		}
//------------------------ 동호회수정------------------------//
	}
	
	function clsControl()
	{
		this.objComm = null;
		
		this.objClubInfo = null
		this.objRole = null;
				
		this.club_seq = null;
		this.club_my = null;
		
		this.objClubName = null;
		this.objClubIntro = null;
		this.objApproval = null;
		this.objKeyword = null;
		this.objCategory = null;
		this.objSkin = null;
		this.objBanner = null;
		this.objLogo = null;		
	}
	
	clsControl.prototype = {
		_init: function(){
			var member_id = _util.getCookie("member_id");
			this.club_seq = _util.getParam("club_seq");
			this.club_my = (_util.getParam("club_my") == "Y") ? 1:0;
			
			if(!this.club_seq) document.location.href = "../club/club.html";
			
			if(!member_id) {
				if(confirm("로그인 후 이용하여 주세요.")){
					_gf.goLogin();						
				}else{
					document.location.href = "../club/club.html";
				}				
			}else if(!this.club_seq) {
				document.location.href = "../club/club.html";
			}
			
			this._preload();
			
			this.objComm = new clsComm();
			this.objClubName = new clsClubName();
			this.objClubIntro = new clsClubIntro();
			this.objApproval = new clsApproval();
			this.objKeyword = new clsKeyword();
			this.objCategory = new clsCategory();
			this.objSkin = new clsSkin();
			this.objBanner = new clsBanner();
			this.objLogo = new clsLogo();
			
			this._beforeStart();
			this._bind();
		}
		, _preload: function(){
			_gf.spinStart();
		}
		, _beforeStart: function(){
			var thisClass = this;
			this._permitStart = {
				
			}
			
			$.ajax({
				url: "js/self_club_top.js"
				, dataType: "script"
				, async: false
				, success: function(){
					
				}
				, error: function(){
					alert("error");
				}
			});
			
			_util.executeThread(function(){
				for(var k in thisClass._permitStart){
					if(!thisClass._permitStart[k]) return false;
				}
				
				return (_clubControl.getClubInfo().infoData);
			}, function(){				
				_gf.spinEnd();;
				thisClass._start();
			});	
		}
		, _role: function(){
			if(!this.objRole.isAdmin()){
				alert(this.objRole.getError());
				document.location.href="home.html?club_seq="+ this.club_seq;
			}
		}
		, _start: function(){		
			this.objClubInfo = _clubControl.getClubInfo();
			this.objRole = new clsRole(this.objClubInfo.infoData);
			this._role();
			
			var thisData = this.objClubInfo.infoData;
			
			this.objClubName.setValue(thisData["동호회명"]);
			this.objClubIntro.setValue(thisData["동호회소개"]);
			this.objApproval.setValue(thisData["가입유형"]);
			this.objApproval.setComment(thisData["가입질문"]);
			this.objKeyword.setValue(thisData["키워드"]);
			this.objCategory.setValue(thisData["카테고리"]);
			this.objSkin.setValue(thisData["상단스킨구분"],thisData["파일"]["상단파일"]);
			this.objBanner.setValue(thisData["배너이미지구분"],thisData["파일"]["배너파일"]);
			this.objLogo.setValue(thisData["로고이미지구분"],thisData["파일"]["로고파일"]);
		}
		, _bind: function(){
			var thisClass = this;
			
			//수정 버튼 이벤트
			$("p.btn_center img[alt=확인]").click(function(event){
				event.preventDefault();	
				var clubName = thisClass.objClubName.getValue();
				var clubIntro = thisClass.objClubIntro.getValue();
				var approval = (thisClass.objApproval.getValue()?"N":"Y");
				var approvalComment = thisClass.objApproval.getComment();
				var keyword = thisClass.objKeyword.getValue();
				var category = thisClass.objCategory.getValue();
				var skin = thisClass.objSkin.getValue();
				var skinGb = thisClass.objSkin.getIdx();
				var banner = thisClass.objBanner.getValue();
				var bannerGb = thisClass.objBanner.getIdx();
				var logo = thisClass.objLogo.getValue();
				var logoGb = thisClass.objLogo.getIdx();
				
				if(!thisClass.objClubName.isValid()){
					alert(thisClass.objClubName.getError());
					thisClass.objClubName.focus();
					return;
				}else if(!thisClass.objClubIntro.isValid()){
					alert(thisClass.objClubIntro.getError());
					thisClass.objClubIntro.focus();
					return;
				}else if(!thisClass.objApproval.isValid()){
					alert(thisClass.objApproval.getError());
					thisClass.objApproval.focus();
					return;
				}else if(!thisClass.objKeyword.isValid()){
					alert(thisClass.objKeyword.getError());
					thisClass.objKeyword.focus();
					return;
				}else if(!thisClass.objCategory.isValid()){
					alert(thisClass.objCategory.getError());
					thisClass.objCategory.focus();
					return;
				}else if(!thisClass.objSkin.isValid()){
					alert(thisClass.objSkin.getError());
					thisClass.objSkin.focus();
					return;
				}else if(!thisClass.objBanner.isValid()){
					alert(thisClass.objBanner.getError());
					thisClass.objBanner.focus();
					return;
				}else if(!thisClass.objLogo.isValid()){
					alert(thisClass.objLogo.getError());
					thisClass.objLogo.focus();
					return;
				}
			
				_gf.spinStart();
				thisClass.objComm.clubSubmit({
																		"동호회키": thisClass.club_seq
																	,"동호회이름": clubName
																	,"동호회소개": clubIntro
																	,"가입승인여부": approval
																	,"가입승인질문": approvalComment
																	,"키워드": keyword
																	,"카테고리": category
																	,"상단스킨": skin
																	,"상단스킨구분": skinGb
																	,"배너이미지": banner
																	,"배너이미지구분": bannerGb
																	,"로고이미지": logo
																	,"로고이미지구분": logoGb
																	});				
			});
			
			//취소 버튼 이벤트
			$("p.btn_center img[alt=취소]").click(function(event){
				event.preventDefault();				
				document.location.href="club_admin_info.html?club_seq="+ thisClass.club_seq;
			});
			
			//동회회이름 중복확인 이벤트
			this.objClubName.$getBtnDuplicate().click(function(event){
				var clubName = thisClass.objClubName.getValue();
				
				thisClass.objClubName.setClubData("클럽명",clubName);
				thisClass.objComm.setClubNameRequest("클럽명",clubName);
				thisClass.objComm.clubNameDuplicate();
			});
			
			//동호회명 중복확인 완료이벤트
			$(this.objComm).bind("evtFinishClubNameDuplicate", function(event, retData){
				_gf.spinEnd();
				alert(retData["메세지"]);					
				if(retData["응답코드"]) {
					thisClass.objClubName.setClubData("클럽명",retData["클럽명"]);
					thisClass.objClubName.setClubData("중복유무",true);
				}else{
					thisClass.objClubName.setClubData("중복유무",false);
					thisClass.objClubName.focus();					
				}								
			});
			
			// 동호회 개설 전송 완료
			$(this.objComm).bind("evtFinishClubSubmit", function(event, retData){
				_gf.spinEnd();				
				alert(retData["메세지"]);				
				if(retData["응답코드"]){
					document.location.href = "../self_club/club_admin_info.html?club_seq=" + thisClass.club_seq;	
				}				
			});
			
		}
	}
	
	document.objControl = new clsControl();
	document.objControl._init();
});	